#include <stddef.h>
#define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
		(type *)( (char *)__mptr - offsetof(type,member) );})

#define list_entry(ptr, type, member) \
	        container_of(ptr, type, member)


struct list_head {
	struct list_head *next, *prev;
};


static inline void __list_del(struct list_head * prev, struct list_head * next)
{
	next->prev = prev;
        prev->next = next;
}

static inline void __list_add(	struct list_head *xnew,
				struct list_head *prev,
				struct list_head *next)
{
	next->prev = xnew;
	xnew->next = next;
	xnew->prev = prev;
	prev->next = xnew;
}


static inline void list_add_tail(	struct list_head *xnew, 
					struct list_head *head)
{
	__list_add(xnew, head->prev, head);
}

static inline void init_list_head(struct list_head *list)
{
	list->next = list;
	list->prev = list;
}
